<?php

require 'Response.php';
require 'DB.php';

$username=$_POST['username'];
$phone=$_POST['phone'];
$password=$_POST['password'];
//$icon=$_POST['icon'];



////3、增加
//$pdo=DB::getInstance()->connect();
//$stmt=$pdo->query("INSERT into `user`(username,phone,password) VALUES ('李四','111','111w')");
//$sql="INSERT into `user`(username,phone,password) VALUES ('$username','$phone','$password')";
//$count=$pdo->exec($sql);


$pdo = DB::getInstance()->connect();
$sql1="SELECT * FROM user WHERE username='$username' ";
$sql2="SELECT * FROM user WHERE phone='$phone' ";
$stmt1=$pdo->query($sql1);
$stmt2=$pdo->query($sql2);

if($stmt1->rowCount()>=1){

    Response::json('-1','用户已存在，请更换用户名！');
}else if($stmt2->rowCount()>=1){
    Response::json('-1','该手机号已被注册过，请登录！');
} else{
    $sql3="INSERT into `user`(username,phone,password) VALUES ('$username','$phone','$password')";
    $sql4="INSERT into `infors`(username) VALUES ('$username')";
    $stmt=$pdo->query($sql3);
    $stmt1=$pdo->query($sql4);
    Response::json('200','注册成功');
}
